//
//  QueryStringPairClass.m
//  objective_c_language
//
//  Created by 龙 on 2018/5/25.
//  Copyright © 2018年 longlong. All rights reserved.
//

#import "QueryStringPairClass.h"
#import "PercentEscaped.h"

@implementation QueryStringPairClass
- (instancetype)initWithField:(id)field value:(id)value {
    self = [super init];
    if (!self) {
        return nil;
    }
    
    self.field = field;
    self.value = value;
    
    return self;
}

- (NSString *)URLEncodedStringValue {
    if (!self.value || [self.value isEqual:[NSNull null]]) {
        return PercentEscapedStringFromString([self.field description]);
    } else {
        return [NSString stringWithFormat:@"%@=%@", PercentEscapedStringFromString([self.field description]), PercentEscapedStringFromString([self.value description])];
    }
}


@end
